﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Security;
using EM.Repository.utility;
using System.Data;

namespace EM.devel
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            AppPathFinder finder = new AppPathFinder();
            string url = finder.GetApplicationPath();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "SELECT * FROM TBLDEVELOPER WHERE DEVELOPERUSERCODE = @DEVELOPERUSERCODE AND DEVELOPERPASSWORD = @DEVELOPERPASSWORD ";
            cmd.Parameters.AddWithValue("@DEVELOPERPASSWORD", FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "md5"));
            cmd.Parameters.AddWithValue("@DEVELOPERUSERCODE", txtUserName.Text);

            DbHelper helper = new DbHelper();
            DataTable dt = helper.GetDataTable(cmd, "");

            if (dt.Rows.Count > 0)
            {
                Session["DEVELOPERID"] = dt.Rows[0]["DEVELOPERID"].ToString();
                Session["DEVELOPERUSERCODE"] = dt.Rows[0]["DEVELOPERUSERCODE"].ToString();
                Session["HASDEVELOPERACCESS"] = true;

                Response.Redirect(url + "/default.aspx");
            }
            else
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('Hatalı kullanıcı adı yada şifre!');", true);
            }
        }
    }
}